#!/bin/bash

set -e

NIGHTLY="nightly-2025-01-16"

rustup toolchain install $NIGHTLY
rustup default $NIGHTLY
rustup toolchain install $NIGHTLY-x86_64-apple-darwin --force-non-host
rustup toolchain install $NIGHTLY-aarch64-apple-darwin --force-non-host
rustup component add rust-src --toolchain $NIGHTLY-aarch64-apple-darwin
rustup component add rust-src --toolchain $NIGHTLY-x86_64-apple-darwin
if [[ $(uname -s) == "Linux" ]]; then
  rustup component add rust-src --toolchain $NIGHTLY-$(uname -m)-unknown-linux-gnu
fi

# Android
rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android
# iOS
rustup target add aarch64-apple-darwin x86_64-apple-darwin
# macOS
rustup target add x86_64-apple-ios aarch64-apple-ios-sim aarch64-apple-ios
# Wasm
rustup target add wasm32-unknown-emscripten

cargo install cbindgen --locked

if [[ "$1" == "dev" ]]; then
  rustup component add llvm-tools-preview clippy rustfmt
  cargo install cargo-llvm-cov --locked
fi
